import '../public/index'
import url from '../data/url'
import request from '../data/request'
import {tableConfig, header} from '../data/config'
import store from 'store'

const base           = url.base,
      getFeedBackPage = request.getFeedBackPage,
      getChannelList = request.getChannelList;

let table,
    clickEle,
    clickData

// 初始化表格
table = $('#table').bootstrapTable($.extend({}, tableConfig, {
  url: base + getFeedBackPage,
  queryParams: function (params) {
    return $.extend({
      currentPage: params.pageNumber,
      pageSize: params.pageSize
    }, $('#searchForm').serializeObject())
  },
  columns: [
    {
      field: 'name',
      title: '返回人',
      valign: 'middle'
    }, {
      field: 'rawAddTime',
      title: '返回时间',
      valign: 'middle',
      formatter: (index, row) => {
        return moment(index).format('YYYY-MM-DD HH:mm:ss')
      }
    }, {
      field: 'content',
      title: '返回内容',
      valign: 'middle'
    }, {
      field: 'action',
      valign: 'middle',
      align: 'center',
      title: '操作',
      formatter: function (index, row) {
        return `<div class="btn-group">
                      <button type="button" data-id="${row.idStr}" class="btn btn-default btn-detail">详情</button>                  
                </div>`
      }
    }]
}))

// 点击列表的时候传递数据到全局变量
table.on('click-row.bs.table', (e, data, el) => {
  clickEle  = el
  clickData = data
})

// 搜索
$('#search-btn').on('click', (e) => {
  e.preventDefault();

  table.bootstrapTable('refresh', {
    query: $.extend({
      currentPage: 1,
    }, $('#searchForm').serializeObject())
  })
})

// 详情
$(document).on('click', '#table .btn-detail', (e) => {
  e.preventDefault()

  store.set('storeData', clickData) // 存储当前点击的数据到缓存，在修改页面再获取

  window.location = './detail.html?id=' + clickData .id

  console.log('详情');
})
